package Aim_at_Offer;/*
 *  Author: Ksxy
 *  Date: 2018/3/25
 *  Version: 1.0
 *  Description:
 */

import java.util.ArrayList;

public class PrintListFrom {
    public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {

        ArrayList<Integer> r = new ArrayList<>();
        if(listNode != null){
            reverseListFrom(listNode, r);
        }
        return r;
    }

    private void reverseListFrom(ListNode listNode, ArrayList<Integer> result){
        if(listNode.next != null){
            reverseListFrom(listNode.next, result);
        }
        result.add(listNode.val);
    }

    public class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }
}
